<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card class="box-card">
        <el-input style="width:30%" placeholder="请输入内容" v-model="queryData.query" class="input-with-select">
          <el-button slot="append" icon="el-icon-search"></el-button>
        </el-input>
        <el-table :data="orders" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="订单价格" prop="order_price">
          <template  slot-scope="scope">
            <el-tag v-if="scope.row.pay_status=='1'" type="success">已付款</el-tag>
            <el-tag v-else type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | formatDate }}
          </template>
        </el-table-column>
        <el-table-column label="操作" prop="order_price" width="250px">
          <template>
            <el-button size="mini" type="primary" icon="el-icon-edit" circle @click="editAddress">修改地址</el-button>
            <el-button size="mini" type="success" icon="el-icon-location" circle @click="showProcess">物流进度</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryData.pagenum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="queryData.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog
    title="修改地址"
    :visible.sync="editAddressdialogVisible"
    width="50%">
    <el-form :model="form" :rules="rules" ref="editAddressFormRef" label-width="100px" class="demo-ruleForm">
      <el-form-item label="省市区县: " >
        <el-cascader
          v-model="form.addressValue"
          :options="cityData"
          @change="cascaderHandleChange">
        </el-cascader>
      </el-form-item>
      <el-form-item label="详细地址: " >
        <el-input></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
    <el-button @click="editAddressdialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="editAddressdialogVisible = false">确 定</el-button>
    </span>
    </el-dialog>
    <!-- 物流进度对话框 -->
    <el-dialog
      title="物流进度"
      :visible.sync="processDialogVisible"
      width="50%">
      <el-timeline :reverse="false">
        <el-timeline-item
          v-for="(item, index) in processList"
          :key="index"
          :timestamp="item.time">
          {{ item.content }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata.js'
export default {
  data () {
    return {
      queryData: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orders: [],
      total: 0,
      editAddressdialogVisible: false,
      form: {
        addressValue: []
      },
      rules: {},
      cityData,
      processDialogVisible: false,
      processList: []
    }
  },

  created () {
    this.getOrders()
  },

  methods: {
    async getOrders () {
      const { data: res } = await this.$axios.get('orders', {
        params: this.queryData
      })
      // console.log(res)
      if (res.meta.status !== 200) return this.$message.error('获取失败')
      this.orders = res.data.goods
      this.total = res.data.total
      // this.$message.success('获取成功')
    },
    handleSizeChange (val) {
      this.queryData.pagesize = val
      this.getOrders()
    },
    handleCurrentChange (val) {
      this.queryData.pagenum = val
      this.getOrders()
    },
    editAddress () {
      this.editAddressdialogVisible = true
    },
    cascaderHandleChange () {
      console.log(this.form.addressValue)
    },
    async showProcess () {
      this.processDialogVisible = true
      const { data: res } = await this.$axios.get('http://localhost:8080/api/express')
      // console.log(res)
      if (res.meta.status !== 200) return this.$message.error('获取数据失败')
      this.processList = res.data
    }
  }
}
</script>

<style scoped lang='less'>

</style>
